--
-- Author: shunguo.chen
-- Date: 2018-01-09 15:34:35
--
-- CosplayRender 玩家选择render

local HeadRender = require("app.widget.renders.HeadRender")

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node)
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end     
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

-- 
function ClassRef:init(data)
	self.super.init(self, data)
	
	self:setContentSize(self._ui.Panel:getContentSize())

	self._headRender = HeadRender.create(self._ui.head, 3)
	self._myBg = self._ui["Panel/Panel_team/bg_my"]

	self:refresh()
end

-- data = CosplayChoice
function ClassRef:refresh()
	self:setVisible(self._data ~= nil)
	if self._data then
		if self._data:isChoose() then
			local params = self._data:getRoleAvatarParams()
			self._headRender:setData(params)
			self:setSelected(true, params.name)
		else
			self._headRender:setIconVisible(false)
			self:setSelected(false)
		end
		self:setName(self._data:getUserName())
		if self._myBg then
			self._myBg:setVisible(self._data:isMe())
		end
	end
end

function ClassRef:setSelected(b, name)
	self._ui["Panel/Panel_team/icon"]:setVisible(not b)
	if b then
		self._ui.tips:setString(name)
	else
		self._ui.tips:setString(L("lua_code_text_88"))
	end
end

function ClassRef:setName(name)
	self._ui.name:setString(name)
end

function ClassRef:setIsEnemy(b)
	self._headRender:setFaceLeft(b)
end

return ClassRef